import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';
import { MissionSaveTask } from './MissionSaveTask';
import { MissionStatus } from './MissionStatus';
import { ITimer } from '../../api/timer/ITimer';
import { IAsync } from '../../api/event/IAsync';
import { MathUtils } from '../../api/math/MathUtils';



/**任务属性枚举*/
export const enum E_Mission {
	/**统计任务*/
	SAVE_TASK = 0,
	/**任务状态，excel配置的*/
	STATUS = 1,
	/**新兵试炼任务状态*/
	TRIAL_STATUS = 2,
	/**任务类型60的任务 数据更新时间*/
	DAILY_MISSION_UPDATE_TIME = 3,
	/**任务类型60的任务的完成情况*/
	DAILY_MISSION_COMPLETED = 4,
	/**枚举数量*/
	EnumCount = 5
}


/**任务*/
export class Mission {
	/**事件ID*/
	public static readonly EVENT_ID = 'STRUCT_DATA_MISSION_EVENT_ID';
	/**整体更新事件ID（部分只需要监听整体变化）*/
	public static readonly TOTAL_EVENT_ID = 'STRUCT_DATA_MISSION_TOTAL_EVENT_ID';
	/**缓存池*/
	private static POOL: Mission[] = [];

	/**创建入口*/
	public static create(json?: string): Mission {
		const c = this.POOL.pop() || new Mission();
		c._destroyed = false;
		c.resetProperty();
		if (json) {
			c.parse(json);
		}
		return c;
	}


	/**已释放*/
	protected _destroyed = false;
	/**统计任务*/
	protected _saveTask: HashMap<number, MissionSaveTask> = null;
	/**任务状态，excel配置的*/
	protected _status: HashMap<number, MissionStatus> = null;
	/**新兵试炼任务状态*/
	protected _trialStatus: HashMap<number, MissionStatus> = null;
	/**任务类型60的任务 数据更新时间 (long)*/
	protected _dailyMissionUpdateTime: number;
	/**任务类型60的任务的完成情况*/
	protected _dailyMissionCompleted: HashMap<number, boolean> = null;


	/**构建函数-私有，防止外部创建*/
	private constructor() {
	}


	/**释放*/
	public destroy(): void {
		if (this._destroyed) {
			return;
		}
		this._destroyed = true;
		this.resetProperty(true);
		if (Mission.POOL.indexOf(this) === -1) {
			Mission.POOL.push(this);
		}
	}

	/**设置统计任务*/
	public putSaveTask(k: number, v: MissionSaveTask): MissionSaveTask {
		const ov = this._saveTask.put(k, v);
		return ov;
	}


	/**获取统计任务*/
	public getSaveTask(k: number) {
		return this._saveTask.get(k);
	}


	/**删除统计任务*/
	public removeSaveTask(k: number, autoDestroy = false): MissionSaveTask {
		const ov = this._saveTask.remove(k);
		if (autoDestroy && ov) {
			ov.destroy();
		}
		return ov;
	}


	/**获取统计任务映射表-键值(外部改变将导致出错，只能用于遍历)*/
	public getSaveTaskKeys(): number[] {
		return this._saveTask.getKeys();
	}


	/**获取统计任务映射表-值(外部改变将导致出错，只能用于遍历)*/
	public getSaveTaskValues(): MissionSaveTask[] {
		return this._saveTask.getValues();
	}


	/**清空统计任务映射表*/
	public clearSaveTaskMap(autoDestroy = false): void {
		const ks = this._saveTask.getKeys();
		for (let i = ks.length - 1; i >= 0; i--) {
			this.removeSaveTask(ks[i], autoDestroy);
		}
	}


	/**设置任务状态，excel配置的*/
	public putStatus(k: number, v: MissionStatus): MissionStatus {
		const ov = this._status.put(k, v);
		return ov;
	}


	/**获取任务状态，excel配置的*/
	public getStatus(k: number) {
		return this._status.get(k);
	}


	/**删除任务状态，excel配置的*/
	public removeStatus(k: number, autoDestroy = false): MissionStatus {
		const ov = this._status.remove(k);
		if (autoDestroy && ov) {
			ov.destroy();
		}
		return ov;
	}


	/**获取任务状态，excel配置的映射表-键值(外部改变将导致出错，只能用于遍历)*/
	public getStatusKeys(): number[] {
		return this._status.getKeys();
	}


	/**获取任务状态，excel配置的映射表-值(外部改变将导致出错，只能用于遍历)*/
	public getStatusValues(): MissionStatus[] {
		return this._status.getValues();
	}


	/**清空任务状态，excel配置的映射表*/
	public clearStatusMap(autoDestroy = false): void {
		const ks = this._status.getKeys();
		for (let i = ks.length - 1; i >= 0; i--) {
			this.removeStatus(ks[i], autoDestroy);
		}
	}


	/**设置新兵试炼任务状态*/
	public putTrialStatus(k: number, v: MissionStatus): MissionStatus {
		const ov = this._trialStatus.put(k, v);
		return ov;
	}


	/**获取新兵试炼任务状态*/
	public getTrialStatus(k: number) {
		return this._trialStatus.get(k);
	}


	/**删除新兵试炼任务状态*/
	public removeTrialStatus(k: number, autoDestroy = false): MissionStatus {
		const ov = this._trialStatus.remove(k);
		if (autoDestroy && ov) {
			ov.destroy();
		}
		return ov;
	}


	/**获取新兵试炼任务状态映射表-键值(外部改变将导致出错，只能用于遍历)*/
	public getTrialStatusKeys(): number[] {
		return this._trialStatus.getKeys();
	}


	/**获取新兵试炼任务状态映射表-值(外部改变将导致出错，只能用于遍历)*/
	public getTrialStatusValues(): MissionStatus[] {
		return this._trialStatus.getValues();
	}


	/**清空新兵试炼任务状态映射表*/
	public clearTrialStatusMap(autoDestroy = false): void {
		const ks = this._trialStatus.getKeys();
		for (let i = ks.length - 1; i >= 0; i--) {
			this.removeTrialStatus(ks[i], autoDestroy);
		}
	}


	/**任务类型60的任务 数据更新时间*/
	public get dailyMissionUpdateTime() {
		return this._dailyMissionUpdateTime;
	}


	/**任务类型60的任务 数据更新时间*/
	public set dailyMissionUpdateTime(v: number) {
		this._dailyMissionUpdateTime = v;
	}


	/**设置任务类型60的任务的完成情况*/
	public putDailyMissionCompleted(k: number, v: boolean): boolean {
		const ov = this._dailyMissionCompleted.put(k, v);
		return ov;
	}


	/**获取任务类型60的任务的完成情况*/
	public getDailyMissionCompleted(k: number) {
		return this._dailyMissionCompleted.get(k);
	}


	/**删除任务类型60的任务的完成情况*/
	public removeDailyMissionCompleted(k: number): boolean {
		const ov = this._dailyMissionCompleted.remove(k);
		return ov;
	}


	/**获取任务类型60的任务的完成情况映射表-键值(外部改变将导致出错，只能用于遍历)*/
	public getDailyMissionCompletedKeys(): number[] {
		return this._dailyMissionCompleted.getKeys();
	}


	/**获取任务类型60的任务的完成情况映射表-值(外部改变将导致出错，只能用于遍历)*/
	public getDailyMissionCompletedValues(): boolean[] {
		return this._dailyMissionCompleted.getValues();
	}


	/**清空任务类型60的任务的完成情况映射表*/
	public clearDailyMissionCompletedMap(): void {
		this._dailyMissionCompleted.clear();
	}



	/**通过枚举获取值*/
	public getV(k: E_Mission): any {
		switch (k) {
			case E_Mission.SAVE_TASK: return this._saveTask;
			case E_Mission.STATUS: return this._status;
			case E_Mission.TRIAL_STATUS: return this._trialStatus;
			case E_Mission.DAILY_MISSION_UPDATE_TIME: return this._dailyMissionUpdateTime;
			case E_Mission.DAILY_MISSION_COMPLETED: return this._dailyMissionCompleted;
			default: return null;
		}
	}


	/**通过枚举设置值*/
	public setV(k: E_Mission, v: any): void {
		switch (k) {
			case E_Mission.SAVE_TASK: this._saveTask = v; break;
			case E_Mission.STATUS: this._status = v; break;
			case E_Mission.TRIAL_STATUS: this._trialStatus = v; break;
			case E_Mission.DAILY_MISSION_UPDATE_TIME: this._dailyMissionUpdateTime = v; break;
			case E_Mission.DAILY_MISSION_COMPLETED: this._dailyMissionCompleted = v; break;
			default: break;
		}
	}


	/**初始化*/
	public resetProperty(fromDestroy = false): void {
		//统计任务
		if (this._saveTask) {
			const list = this._saveTask.getValues();
			for (let i = 0, len = list.length; i < len; i++) {
				list[i].destroy();
			}
			this._saveTask.clear();
		}
		else {
			this._saveTask = new HashMap<number, MissionSaveTask>();
		}
		//任务状态，excel配置的
		if (this._status) {
			const list = this._status.getValues();
			for (let i = 0, len = list.length; i < len; i++) {
				list[i].destroy();
			}
			this._status.clear();
		}
		else {
			this._status = new HashMap<number, MissionStatus>();
		}
		//新兵试炼任务状态
		if (this._trialStatus) {
			const list = this._trialStatus.getValues();
			for (let i = 0, len = list.length; i < len; i++) {
				list[i].destroy();
			}
			this._trialStatus.clear();
		}
		else {
			this._trialStatus = new HashMap<number, MissionStatus>();
		}
		//任务类型60的任务 数据更新时间
		this._dailyMissionUpdateTime = 0;
		//任务类型60的任务的完成情况
		if (this._dailyMissionCompleted) {
			this._dailyMissionCompleted.clear();
		}
		else {
			this._dailyMissionCompleted = new HashMap<number, boolean>();
		}
	}


	/**序列化*/
	public stringify(toString: boolean): string | any {
		const json: any = {};
		if (this._saveTask.size() > 0) {
			const ks = this._saveTask.getKeys();
			const vs = this._saveTask.getValues();
			const list: string[] = [];
			for (let i = 0, len = vs.length; i < len; i++) {
				list[i] = vs[i].stringify(false);
			}
			json.saveTask = [ks, list];
		}
		if (this._status.size() > 0) {
			const ks = this._status.getKeys();
			const vs = this._status.getValues();
			const list: string[] = [];
			for (let i = 0, len = vs.length; i < len; i++) {
				list[i] = vs[i].stringify(false);
			}
			json.status = [ks, list];
		}
		if (this._trialStatus.size() > 0) {
			const ks = this._trialStatus.getKeys();
			const vs = this._trialStatus.getValues();
			const list: string[] = [];
			for (let i = 0, len = vs.length; i < len; i++) {
				list[i] = vs[i].stringify(false);
			}
			json.trialStatus = [ks, list];
		}
		if (this._dailyMissionUpdateTime) {
			json.dailyMissionUpdateTime = this._dailyMissionUpdateTime;
		}
		if (this._dailyMissionCompleted.size() > 0) {
			const ks = this._dailyMissionCompleted.getKeys();
			const vs = this._dailyMissionCompleted.getValues();
			json.dailyMissionCompleted = [ks, vs];
		}

		return toString ? JSON.stringify(json) : json;
	}


	/**反序列化*/
	public parse(jsonv: string | any): this {
		this.resetProperty();
		if (!jsonv) {
			return this;
		}
		const json = typeof (jsonv) === 'string' ? JSON.parse(jsonv) : jsonv;
		if (json.saveTask) {
			const ks: number[] = json.saveTask[0] || (json.saveTask.getKeys ? json.saveTask.getKeys() : null);	//对象可能是json或者结构体
			const vs: string[] = json.saveTask[1] || (json.saveTask.getValues ? json.saveTask.getValues() : null);
			if (ks && vs && ks.length === vs.length) {
				for (let i = 0, len = vs.length; i < len; i++) {
					this._saveTask.put(ks[i], MissionSaveTask.create(vs[i]));
				}
			}
		}
		if (json.status) {
			const ks: number[] = json.status[0] || (json.status.getKeys ? json.status.getKeys() : null);	//对象可能是json或者结构体
			const vs: string[] = json.status[1] || (json.status.getValues ? json.status.getValues() : null);
			if (ks && vs && ks.length === vs.length) {
				for (let i = 0, len = vs.length; i < len; i++) {
					this._status.put(ks[i], MissionStatus.create(vs[i]));
				}
			}
		}
		if (json.trialStatus) {
			const ks: number[] = json.trialStatus[0] || (json.trialStatus.getKeys ? json.trialStatus.getKeys() : null);	//对象可能是json或者结构体
			const vs: string[] = json.trialStatus[1] || (json.trialStatus.getValues ? json.trialStatus.getValues() : null);
			if (ks && vs && ks.length === vs.length) {
				for (let i = 0, len = vs.length; i < len; i++) {
					this._trialStatus.put(ks[i], MissionStatus.create(vs[i]));
				}
			}
		}
		if (json.dailyMissionUpdateTime) {
			this._dailyMissionUpdateTime = json.dailyMissionUpdateTime;
		}
		if (json.dailyMissionCompleted) {
			const ks: number[] = json.dailyMissionCompleted[0];
			const vs: boolean[] = json.dailyMissionCompleted[1];
			if (ks && vs && ks.length === vs.length) {	//json
				this._dailyMissionCompleted.setKeyAndValueList(ks, vs);
			}
			else if (json.dailyMissionCompleted.getKeys && json.dailyMissionCompleted.getValues) {	//结构体
				const ks2 = json.dailyMissionCompleted.getKeys();
				const vs2 = json.dailyMissionCompleted.getValues();
				if (ks2 && vs2 && ks2.length === vs2.length) {
					for (let i = 0, len = vs2.length; i < len; i++) {
						this._dailyMissionCompleted.put(ks2[i], vs2[i]);	//重新添加，防止数据公用后被释放导致bug
					}
				}
			}
		}
		return this;
	}


	/**序列化-二进制*/
	public toBytes(byte: Byte): void {
		if (!byte) {
			return;
		}
		//统计任务
		{
			const ks = this._saveTask.getKeys();
			const vs = this._saveTask.getValues();
			const len = ks.length;
			byte.writeUint16(len);
			for (let i = 0; i < len; i++) {
				byte.writeUint8(ks[i]);
				vs[i].toBytes(byte);
			}
		}
		//任务状态，excel配置的
		{
			const ks = this._status.getKeys();
			const vs = this._status.getValues();
			const len = ks.length;
			byte.writeUint16(len);
			for (let i = 0; i < len; i++) {
				byte.writeLongNumber(ks[i]);
				vs[i].toBytes(byte);
			}
		}
		//新兵试炼任务状态
		{
			const ks = this._trialStatus.getKeys();
			const vs = this._trialStatus.getValues();
			const len = ks.length;
			byte.writeUint16(len);
			for (let i = 0; i < len; i++) {
				byte.writeLongNumber(ks[i]);
				vs[i].toBytes(byte);
			}
		}
		byte.writeLongNumber(this._dailyMissionUpdateTime);
		//任务类型60的任务的完成情况
		{
			const ks = this._dailyMissionCompleted.getKeys();
			const vs = this._dailyMissionCompleted.getValues();
			const len = ks.length;
			byte.writeUint16(len);
			for (let i = 0; i < len; i++) {
				byte.writeLongNumber(ks[i]);
				byte.writeBool(vs[i]);
			}
		}
	}


	/**反序列化-二进制*/
	public fromBytes(byte: Byte): this {
		this.resetProperty();
		if (!byte) {
			return;
		}
		//统计任务
		{
			const len = byte.readUint16();
			for (let i = 0; i < len; i++) {
				const k = byte.readUint8();
				const v = MissionSaveTask.create();
				v.fromBytes(byte);
				this._saveTask.put(k, v);
			}
		}
		//任务状态，excel配置的
		{
			const len = byte.readUint16();
			for (let i = 0; i < len; i++) {
				const k = byte.readLongNumber();
				const v = MissionStatus.create();
				v.fromBytes(byte);
				this._status.put(k, v);
			}
		}
		//新兵试炼任务状态
		{
			const len = byte.readUint16();
			for (let i = 0; i < len; i++) {
				const k = byte.readLongNumber();
				const v = MissionStatus.create();
				v.fromBytes(byte);
				this._trialStatus.put(k, v);
			}
		}
		this._dailyMissionUpdateTime = byte.readLongNumber();
		//任务类型60的任务的完成情况
		{
			const len = byte.readUint16();
			for (let i = 0; i < len; i++) {
				const k = byte.readLongNumber();
				const v = byte.readBool();
				this._dailyMissionCompleted.put(k, v);
			}
		}
		return this;
	}


	/**克隆*/
	public clone(): Mission {
		const byte = Byte.createFromPool();
		this.toBytes(byte);
		byte.pos = 0;
		const clonev = Mission.create().fromBytes(byte);
		Byte.recoverToPool(byte);
		return clonev;
	}


	/**处理更新*/
	public processUpdate(jsonv: string): void {
		if (!jsonv) {
			return;
		}

		const eventID = Mission.EVENT_ID;
		const us = JSON.parse(jsonv);

		for (let i = 0, len = us.length; i < len;) {
			const idx = us[i];

			//统计任务
			if (idx === E_Mission.SAVE_TASK) {
				const k: number = us[i + 1];
				const ctrl: number = us[i + 2];
				if (ctrl === 0) {
					const oldv = this.removeSaveTask(k);
					if (oldv) {
						oldv.destroy()
					}
				}
				else if (ctrl === 1) {
					const newv = MissionSaveTask.create(us[i + 3]);
					const oldv = this.putSaveTask(k, newv);
					if (oldv) {
						oldv.destroy()
					}
				}
				else {
					const curv = this.getSaveTask(k);
					if (curv) {
						curv.processUpdate(us[i + 3]);
					}
					else {
						console.error('Mission MissionSaveTask is not exist when update! k = ' + k);
					}
				}
				IAsync.dispatch(eventID, idx, k, ctrl);
				i += ctrl === 0 ? 3 : 4;
				continue;
			}

			//任务状态，excel配置的
			if (idx === E_Mission.STATUS) {
				const k: number = us[i + 1];
				const ctrl: number = us[i + 2];
				if (ctrl === 0) {
					const oldv = this.removeStatus(k);
					if (oldv) {
						oldv.destroy()
					}
				}
				else if (ctrl === 1) {
					const newv = MissionStatus.create(us[i + 3]);
					const oldv = this.putStatus(k, newv);
					if (oldv) {
						oldv.destroy()
					}
				}
				else {
					const curv = this.getStatus(k);
					if (curv) {
						curv.processUpdate(us[i + 3]);
					}
					else {
						console.error('Mission MissionStatus is not exist when update! k = ' + k);
					}
				}
				IAsync.dispatch(eventID, idx, k, ctrl);
				i += ctrl === 0 ? 3 : 4;
				continue;
			}

			//新兵试炼任务状态
			if (idx === E_Mission.TRIAL_STATUS) {
				const k: number = us[i + 1];
				const ctrl: number = us[i + 2];
				if (ctrl === 0) {
					const oldv = this.removeTrialStatus(k);
					if (oldv) {
						oldv.destroy()
					}
				}
				else if (ctrl === 1) {
					const newv = MissionStatus.create(us[i + 3]);
					const oldv = this.putTrialStatus(k, newv);
					if (oldv) {
						oldv.destroy()
					}
				}
				else {
					const curv = this.getTrialStatus(k);
					if (curv) {
						curv.processUpdate(us[i + 3]);
					}
					else {
						console.error('Mission MissionStatus is not exist when update! k = ' + k);
					}
				}
				IAsync.dispatch(eventID, idx, k, ctrl);
				i += ctrl === 0 ? 3 : 4;
				continue;
			}
			//任务类型60的任务 数据更新时间
			if (idx === E_Mission.DAILY_MISSION_UPDATE_TIME) {
				const oldv = this._dailyMissionUpdateTime;
				this._dailyMissionUpdateTime = us[i + 1];
				IAsync.dispatch(eventID, idx, this._dailyMissionUpdateTime, oldv);
				i += 2;
				continue;
			}

			//任务类型60的任务的完成情况
			if (idx === E_Mission.DAILY_MISSION_COMPLETED) {
				const k: number = us[i + 1];
				const newv :boolean = us[i + 2];
				const oldv = this.putDailyMissionCompleted(k, newv);
				IAsync.dispatch(eventID, idx, k, newv, oldv);
				i += 3;
				continue;
			}

			console.error('[Struct Data] can not find enum in Mission with idx = ' + idx + ', version maybe wrong.')
		}

		//全更事件
		ITimer.callLater(this, this.dispatchTotalUpdate);
	}


	/**比对不一致结果*/
	public getCompareInfo(other: Mission): string {
		if (!other) {
			return null;
		}

		const updates: any[] = [];


		//统计任务
		{
			const idx = E_Mission.SAVE_TASK;
			const ks1 = this._saveTask.getKeys();
			const ks2 = other._saveTask.getKeys();
			const rs = MathUtils.intersectSortedArray(ks1, ks2);
			if (rs[0].length > 0) {
				const list = rs[0];
				for (let i = 0, len = list.length; i < len; i++) {
					const k = list[i];
					const newv = this.getSaveTask(k);
					const oldv = other.getSaveTask(k);
					const ui = newv.getCompareInfo(oldv);
					if (ui && ui.length > 0) {
						updates.push(idx, k, 2, ui);
					}
				}
			}
			if (rs[1].length > 0) {
				const list = rs[1];
				for (let i = 0, len = list.length; i < len; i++) {
					const k = list[i];
					const newv = this.getSaveTask(k);
					updates.push(idx, k, 1, newv.stringify(false));
				}
			}
			if (rs[2].length > 0) {
				const list = rs[2];
				for (let i = 0, len = list.length; i < len; i++) {
					updates.push(idx, list[i], 0);
				}
			}
		}

		//任务状态，excel配置的
		{
			const idx = E_Mission.STATUS;
			const ks1 = this._status.getKeys();
			const ks2 = other._status.getKeys();
			const rs = MathUtils.intersectSortedArray(ks1, ks2);
			if (rs[0].length > 0) {
				const list = rs[0];
				for (let i = 0, len = list.length; i < len; i++) {
					const k = list[i];
					const newv = this.getStatus(k);
					const oldv = other.getStatus(k);
					const ui = newv.getCompareInfo(oldv);
					if (ui && ui.length > 0) {
						updates.push(idx, k, 2, ui);
					}
				}
			}
			if (rs[1].length > 0) {
				const list = rs[1];
				for (let i = 0, len = list.length; i < len; i++) {
					const k = list[i];
					const newv = this.getStatus(k);
					updates.push(idx, k, 1, newv.stringify(false));
				}
			}
			if (rs[2].length > 0) {
				const list = rs[2];
				for (let i = 0, len = list.length; i < len; i++) {
					updates.push(idx, list[i], 0);
				}
			}
		}

		//新兵试炼任务状态
		{
			const idx = E_Mission.TRIAL_STATUS;
			const ks1 = this._trialStatus.getKeys();
			const ks2 = other._trialStatus.getKeys();
			const rs = MathUtils.intersectSortedArray(ks1, ks2);
			if (rs[0].length > 0) {
				const list = rs[0];
				for (let i = 0, len = list.length; i < len; i++) {
					const k = list[i];
					const newv = this.getTrialStatus(k);
					const oldv = other.getTrialStatus(k);
					const ui = newv.getCompareInfo(oldv);
					if (ui && ui.length > 0) {
						updates.push(idx, k, 2, ui);
					}
				}
			}
			if (rs[1].length > 0) {
				const list = rs[1];
				for (let i = 0, len = list.length; i < len; i++) {
					const k = list[i];
					const newv = this.getTrialStatus(k);
					updates.push(idx, k, 1, newv.stringify(false));
				}
			}
			if (rs[2].length > 0) {
				const list = rs[2];
				for (let i = 0, len = list.length; i < len; i++) {
					updates.push(idx, list[i], 0);
				}
			}
		}
		if (this._dailyMissionUpdateTime !== other._dailyMissionUpdateTime) {
			updates.push(E_Mission.DAILY_MISSION_UPDATE_TIME, this._dailyMissionUpdateTime);
		}

		//任务类型60的任务的完成情况
		{
			const idx = E_Mission.DAILY_MISSION_COMPLETED;
			const ks1 = this._dailyMissionCompleted.getKeys();
			const ks2 = other._dailyMissionCompleted.getKeys();
			const vs1 = this._dailyMissionCompleted.getValues();
			const vs2 = other._dailyMissionCompleted.getValues();
			const rs = MathUtils.intersectSortedArray(ks1, ks2, vs1, vs2);
			if (rs[0].length > 0) {
				const list = rs[0];
				for (let i = 0, len = list.length; i < len; i++) {
					const k = list[i];
					const newv = this.getDailyMissionCompleted(k);
					updates.push(idx, k, newv);
				}
			}
			if (rs[1].length > 0) {
				const list = rs[1];
				for (let i = 0, len = list.length; i < len; i++) {
					const k = list[i];
					const newv = this.getDailyMissionCompleted(k);
					updates.push(idx, k, newv);
				}
			}
			if (rs[2].length > 0) {
				const list = rs[2];
				for (let i = 0, len = list.length; i < len; i++) {
					updates.push(idx, list[i], 0);
				}
			}
		}

		const jsonv = updates.length === 0 ? null : JSON.stringify(updates);
		return jsonv;
	}


	/**全部更新*/
	protected dispatchTotalUpdate(): void {
		IAsync.dispatch(Mission.TOTAL_EVENT_ID, this.getV(0));
	}

}
